package edu.cicese.alz.reports;

import edu.cicese.alz.TimeUtil;

import java.util.Calendar;
import java.util.Date;
import java.util.TreeSet;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 8/08/12
 * Time: 04:37 PM
 */
public class Report {
	protected TreeSet<Integer> userIDs;

	protected long tsBegin, tsEnd;
	protected int beginHour, beginMinute, beginSecond;
	protected int endHour, endMinute, endSecond;

	protected int days;
	protected int periods;

	protected long startTime;

	protected boolean showCharts, saveCharts;

	protected final int PERIOD_LENGTH = 60000;

	public Report(TreeSet<Integer> userIDs, Date beginDate, Date endDate, Date dayBeginDate, Date dayEndDate, boolean showCharts, boolean saveCharts) {
		this(userIDs, dayBeginDate, dayEndDate, showCharts, saveCharts);

		tsBegin = beginDate.getTime();
		tsEnd = TimeUtil.getAdjustedTimestamp(endDate.getTime(), 24, 0, 0);

		days = TimeUtil.getDayDifference(tsBegin, tsEnd - 1);
		periods = (endHour - beginHour) * 60 + (endMinute - beginMinute);
		startTime = (beginHour * 3600000) + (beginMinute * 60000);
	}

	public Report() {
	}

	public Report(TreeSet<Integer> userIDs, Date dayBeginDate, Date dayEndDate, boolean showCharts, boolean saveCharts) {
		this.userIDs = userIDs;
		this.showCharts = showCharts;
		this.saveCharts = saveCharts;

		getValues(dayBeginDate, dayEndDate);
	}

	/*public Report(TreeSet<Integer> userIDs, Date beginDate, Date endDate, Date dayBeginDate, Date dayEndDate) {
		this.userIDs = userIDs;
		tsBegin = beginDate.getTime();
		tsEnd = TimeUtil.getAdjustedTimestamp(endDate.getTime(), 24, 0, 0);

		getValues(dayBeginDate, dayEndDate);
		days = TimeUtil.getDayDifference(tsBegin, tsEnd - 1);
		periods = (endHour - beginHour) * 60 + (endMinute - beginMinute);

	}*/

	public Report(long tsBegin, long tsEnd, int beginHour, int beginMinute, int beginSecond, int endHour, int endMinute, int endSecond, int days, int periods) {
		this.tsBegin = tsBegin;
		this.tsEnd = tsEnd;
		this.beginHour = beginHour;
		this.beginMinute = beginMinute;
		this.beginSecond = beginSecond;
		this.endHour = endHour;
		this.endMinute = endMinute;
		this.endSecond = endSecond;
		this.days = days;
		this.periods = periods;
	}

	private void getValues(Date dayBeginDate, Date dayEndDate) {
		beginHour = TimeUtil.getCalendar(dayBeginDate).get(Calendar.HOUR_OF_DAY);
		beginMinute = TimeUtil.getCalendar(dayBeginDate).get(Calendar.MINUTE);
		beginSecond = TimeUtil.getCalendar(dayBeginDate).get(Calendar.SECOND);
		endHour = TimeUtil.getCalendar(dayEndDate).get(Calendar.HOUR_OF_DAY);
		endHour = endHour == 0 ? 24 : endHour;
		endMinute = TimeUtil.getCalendar(dayEndDate).get(Calendar.MINUTE);
		endSecond = TimeUtil.getCalendar(dayEndDate).get(Calendar.SECOND);
	}
}
